using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace CocaCola_Inventory_System.Data_Access
{
    class Registery
    {
        public static bool saveConnectionString(string Str)
        {
            try
            {
                RegistryKey OurKey = Registry.LocalMachine;
                OurKey = OurKey.CreateSubKey("Software");
                OurKey = OurKey.CreateSubKey("CIS");

                string Encrypted = RijndaelSimple.Encrypt(Str, "YaoGuc", "InventorySystem", "MD5", 2, "abcdabcdabcdabcd", 128);

                OurKey.SetValue("Str", Encrypted);
                return true;
            }
            catch (Exception ex)
            {

                return false;
            }

        }

        public static string GetConnectionString()
        {
            RegistryKey OurKey = Registry.LocalMachine;
            OurKey = OurKey.OpenSubKey("Software");
            OurKey = OurKey.OpenSubKey("CIS");
            if (OurKey == null)
                return null;

            object o = OurKey.GetValue("Str");
            if (o != null)
                return RijndaelSimple.Decrypt(o.ToString(), "YaoGuc", "InventorySystem", "MD5", 2, "abcdabcdabcdabcd", 128);
            else
                return null;
        }
    }
}
